#!/bin/bash

. env.sh

echo DEPLOY_PROFILE=${DEPLOY_PROFILE}
echo DEPLOY_NETWORK=${DEPLOY_NETWORK}
echo DEPLOY_DOMAIN=${DEPLOY_DOMAIN}
echo IMAGE_NAME=${IMAGE_NAME}
echo DEPLOY_STACK_NAME=${DEPLOY_STACK_NAME}

docker build --tag ${IMAGE_NAME}:${CI_PIPELINE_ID} .
docker rmi -f ${IMAGE_NAME}:latest
docker tag ${IMAGE_NAME}:${CI_PIPELINE_ID} ${IMAGE_NAME}:latest
docker rmi -f ${IMAGE_NAME}:${CI_PIPELINE_ID}
docker service rm ${DEPLOY_STACK_NAME}_wj-demo || echo remove service
docker stack deploy -c docker-compose.yml ${DEPLOY_STACK_NAME}